#pragma once

#include "ThreadHlpr.h"
#include "TwoPointDrawElem.h"
#include "ApproachDrawerHolder.h"

class CProg2View : public CView
{
	typedef boost::shared_ptr<CBitmap> CBitmapPtr;

protected: // create from serialization only
	CProg2View();
	DECLARE_DYNCREATE(CProg2View)
	DECLARE_MESSAGE_MAP()
// Attributes
public:
	CProg2Doc* GetDocument() const;

	bool AppendTraceApproaches(CApproachTrace::Ptr listApprc);
public:
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSize(UINT nType, int cx, int cy);

	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnInitialUpdate();
// Implementation
public:
	virtual ~CProg2View();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	void RequestRedraw();
	unsigned ReDrawFunc(CEvent& evtTerminate);
	bool ReDrawAll();
	bool DrawGrid(CDC &cdc, int nWidth, int nHeight);
	bool DrawApproachs(CDC &cdc, int nWidth, int nHeight);

	bool SearchNearestApp(CPoint point);
	bool ShowToolTip(CPoint point, LPCTSTR stzText);
	bool HideToolTip();

protected:
	CEvent				m_evntRedraw;
	CCriticalSection	m_csDrawingBitmap;
	CBitmapPtr			m_phDrawingBitmap;

	CThreadHlpr<CProg2View>	m_ThreadReDraw;	

	CLine				m_lineMouse;
	MSelectRect			m_selectedRect;
	CPoint				m_pointBeginSelection;
	CGridParam			m_GridParam;
	CApproachDrawerHolder m_ApproachHolder;

	auto_ptr<CWnd>		m_pWndToolTip;
	bool				m_bToolTipShown;	
	CBrush				m_brushToolTipBkgd;
	CPoint				m_prevPoint;
	CFont				m_font;
};

#ifndef _DEBUG  // debug version in Prog2View.cpp
inline CProg2Doc* CProg2View::GetDocument() const
   { return reinterpret_cast<CProg2Doc*>(m_pDocument); }
#endif

